*************************************************************************
*																		*
*					Campaign Panel Book Chapter 6 - Communication variables				*
*																		*
*************************************************************************	

use "${data}\ZA5704_en_v3-2-0.dta", clear


/*
Basic reasoning
Replacement for points in time before an event took place:
•	If purely the measurement of reception is of interest, a 0 is imputed
•	If the evaluation of the event is measured, a neutral evaluation (0.5) is
	imputed.

Replacement for points in time after an event took place:
•	If purely the measurement of reception is of interest and the information whether
	the event has taken place, data is collected only in the wave following the 
	event and for all following waves this reception measure (0 or 1) is imputed
•	If the evaluation of the event is supposed to be measured and this evaluation
	is only asked for in one wave (the one directly following the event), the 
	measurement from this wave is imputed in all following waves	

Point in time when the event to place is unequivocal for media events like the
TV-debate, the election arena or even the Wahlomat. For other events this is
much more difficult. Problem: If an event already happened and could have been
evaluated but was not yet included in the campaign panel, replacing the 
evaluation of the event with a neutral value does not make sense. If an event has
taken place, why should all respondents possess a neutral attitude towards it? 
Instead an individual value from a following wave should be imputed. 
Assumption: Constant attitudes. 
Problem: There are some event evaluations which were only measured in one wave
(e.g., Merkel responding to the drone-affair in W3 or Wulff law suit justified in
W5). Both events, however, already began before their measurement in the campaign
panel and respondents probably already established attitudes towards them.
If we undertake the replacement of values for the missing waves in the manner
described above, we do not have any variation over time.
*/


*******************************************************************************
* Supplementary recoding to value range 0-1, partially not necessary since 
* variables are dichotomous
*******************************************************************************
   
*******************************************************************************
** III.5 TV-debate
*******************************************************************************

// For CDU/CSU (Union) and SPD in waves 1-4: tvduell = 3 (neutral)

foreach welle of numlist 1/4 {
   foreach partei of numlist 1 4 {
      gen tvduell`partei'`welle' = 3

}
}

// For Union/SPD in waves 5-7: 3 if not seen, otherwise use evaluation

mvdecode kp?_1810 kp?_1820, mv(-99/-1) 

foreach welle of numlist 5/7 {
   foreach partei of numlist 1 {
      gen tvduell`partei'`welle' = (kp`welle'_1810-6)*-1
	  replace tvduell`partei'`welle' = 3 if (kp5_1800==3)	 //kp5_1800=3 means: never seen (not only in W5)
}
}

foreach welle of numlist 5/7 {
   foreach partei of numlist 4 {
      gen tvduell`partei'`welle' = (kp`welle'_1820-6)*-1
	  replace tvduell`partei'`welle' = 3 if (kp5_1800==3) 
}
}

tab tvduell15

foreach welle of numlist 1/7 {
	foreach partei of numlist 1 4  {
	replace tvduell`partei'`welle'=(tvduell`partei'`welle'-1)/4
	}
}
sum tvduell1?

list tvduell1?


*******************************************************************************
** III.5 TV-debate (network)
*******************************************************************************

// For all parties besides Union/SPD: tvduell = 3 (neutral)

foreach welle of numlist 1/4 {
   foreach partei of numlist 1 4 {
      gen tvduell_su`partei'`welle' = 3
}
}


// For Union/SPD in waves 5-7: 3 if social environment did not talk about it
mvdecode kp?_1910 kp?_1920, mv(-99/-1) 

foreach welle of numlist 5/7 {
   foreach partei of numlist 1 {
      gen tvduell_su`partei'`welle' = (kp`welle'_1910-6)*-1 ///
	     if kp`welle'_1910<=5	 
	replace tvduell_su`partei'`welle' = 3 if kp`welle'_1900==3		
}
}


foreach welle of numlist 5/7 {
   foreach partei of numlist 4 {
      gen tvduell_su`partei'`welle' = (kp`welle'_1920-6)*-1 ///
	     if kp`welle'_1920<=5	 
	replace tvduell_su`partei'`welle' = 3 if kp`welle'_1900==3
}
}

tab tvduell_su15

foreach welle of numlist 1/7 {
	foreach partei of numlist 1 4 {
	replace tvduell_su`partei'`welle'=(tvduell_su`partei'`welle'-1)/4
	}
}
sum tvduell_su??


*******************************************************************************
** III.5 TV-debate (Media)
*******************************************************************************



foreach welle of numlist 1/4 {
   foreach partei of numlist 1 4 {
      gen tvduell_md`partei'`welle' = 3
     
}
}

// For Union/SPD in waves 5-7: 3 if not seen, otherwise use evaluation

mvdecode kp?_1880 kp?_1890, mv(-99/-1) 

foreach welle of numlist 5/7 {
   foreach partei of numlist 1 {
      gen tvduell_md`partei'`welle' = (kp`welle'_1880-6)*-1 ///
	     if kp`welle'_1880<=5	
	replace tvduell_md`partei'`welle' = 3 if kp`welle'_1870==2	     
}
}

foreach welle of numlist 5/7 {
   foreach partei of numlist 4 {
      gen tvduell_md`partei'`welle' = (kp`welle'_1890-6)*-1 ///
	     if kp`welle'_1890<=5	
	replace tvduell_md`partei'`welle' = 3 if kp`welle'_1870==2
	   
}
}

tab tvduell_md15

foreach welle of numlist 1/7 {
	foreach partei of numlist 1 4 {
	replace tvduell_md`partei'`welle'=(tvduell_md`partei'`welle'-1)/4
	}
}
sum tvduell_md??

********************************************************************************
**
** Wahl-O-Mat
**
********************************************************************************
 
 * Nobody could use the Wahl-O-Mat in waves 1 - 4
 foreach welle of numlist 1/4 {
   foreach partei of numlist 1 4/7 {
      gen wahlomat`partei'`welle' = 0
   }
}

fre kp?_3510*

* Fill in responses beginning in wave 5.
* this is dependent interviewing, if once the answer is positive the question
* will not be asked anymore
* 1 for particular party
* 0 for "other" party, if Wahl-O-Mat was not used or is not known
* . in case of refusal, no interview
* if Wahl-O-Mat was once = 1, this cannot change anymore -> constant

foreach welle of numlist 5/7 {
   foreach partei of numlist 1 4/7 {
      gen wahlomat`partei'`welle' =  kp5_3510==`partei'
	  replace wahlomat`partei'`welle' = . if ///
		inlist(kp5_3490, -99, -95, -93) | ///
		inlist(kp5_3510, -99, -95, -93)
}
} 

list kp?_3490 kp?_3510 wahlomat4? in 1/100


foreach welle of numlist 6/7 {
   foreach partei of numlist 1 4/7 {
      replace wahlomat`partei'`welle' =  kp6_3510==`partei' if kp5_3490!=1
	  replace wahlomat`partei'`welle' = . if ///
		inlist(kp6_3490, -99, -95, -93) | ///
		inlist(kp6_3510, -99, -95, -93)
}
}  

list kp?_3490 kp?_3510 wahlomat4? in 1/100

foreach welle of numlist 7 {
   foreach partei of numlist 1 4/7 {
      replace wahlomat`partei'`welle' =  kp7_3510==`partei' if kp5_3490!=1 & kp6_3490!=1
	  replace wahlomat`partei'`welle' = . if ///
		inlist(kp7_3490, -99, -95) | ///
		inlist(kp7_3510, -99, -95, -93)
}
} 

list kp?_3490 kp?_3510 wahlomat4? in 1/100
 

fre wahlomat4?

list kp?_3510
   
********************************************************************************
**
** Talks about politics
**
********************************************************************************


foreach welle of numlist 2/7 {
   gen gespr1`welle' = kp`welle'_1970==1 if ///
      inlist(kp`welle'_1970,-97, -98, -85, 1, 4, 5, 6, 7, 801)
   gen gespr4`welle' = kp`welle'_1970==4 if ///
      inlist(kp`welle'_1970,-97, -98, -85, 1, 4, 5, 6, 7, 801)
   gen gespr5`welle' = kp`welle'_1970==5 if ///
      inlist(kp`welle'_1970,-97, -98, -85, 1, 4, 5, 6, 7, 801)
   gen gespr6`welle' = kp`welle'_1970==6 if ///
      inlist(kp`welle'_1970,-97, -98, 1, 4, 5, 6, 7, 801)
   gen gespr7`welle' = kp`welle'_1970==7 if ///
      inlist(kp`welle'_1970,-97, -98, -85, 1, 4, 5, 6, 7, 801)
}

* Assumption: constant from wave 1 to wave 2
  foreach partei of numlist 1 4/7 {
     gen gespr`partei'1 = gespr`partei'2
  }
  
 sum gespr??
fre gespr1?


********************************************************************************
**
** Party contacts: campaign events
**
********************************************************************************


// Neutral values

foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_kundgeb`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_kundgeb1`welle'= kp`welle'_421aa==1 
   replace pk_kundgeb4`welle'= kp`welle'_421ac==1 
   replace pk_kundgeb5`welle'= kp`welle'_421ad==1 
   replace pk_kundgeb6`welle'= kp`welle'_421ae==1 
   replace pk_kundgeb7`welle'= kp`welle'_421af==1 
}

tab pk_kundgeb15

********************************************************************************
**
** Party contacts: website
**
********************************************************************************

// Neutral values

foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_website`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_website1`welle'= kp`welle'_421ka==1
   replace pk_website4`welle'= kp`welle'_421kc==1 
   replace pk_website5`welle'= kp`welle'_421kd==1 
   replace pk_website6`welle'= kp`welle'_421ke==1 
   replace pk_website7`welle'= kp`welle'_421kf==1 
}

********************************************************************************
**
** Party contacts: election poster
**
********************************************************************************

// Neutral values

foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_plakat`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_plakat1`welle'= kp`welle'_421ga==1
   replace pk_plakat4`welle'= kp`welle'_421gc==1 
   replace pk_plakat5`welle'= kp`welle'_421gd==1 
   replace pk_plakat6`welle'= kp`welle'_421ge==1 
   replace pk_plakat7`welle'= kp`welle'_421gf==1 
}


********************************************************************************
**
** Party contacts: TV ads
**
********************************************************************************

// Neutral values

foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_tvspot`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_tvspot1`welle'= kp`welle'_421da==1
   replace pk_tvspot4`welle'= kp`welle'_421dc==1 
   replace pk_tvspot5`welle'= kp`welle'_421dd==1 
   replace pk_tvspot6`welle'= kp`welle'_421de==1 
   replace pk_tvspot7`welle'= kp`welle'_421df==1 
}


********************************************************************************
**
** Party contacts: radio
**
********************************************************************************

// Neutral values

foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_radio`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_radio1`welle'= kp`welle'_421ea==1
   replace pk_radio4`welle'= kp`welle'_421ec==1 
   replace pk_radio5`welle'= kp`welle'_421ed==1 
   replace pk_radio6`welle'= kp`welle'_421ee==1 
   replace pk_radio7`welle'= kp`welle'_421ef==1 
}

********************************************************************************
**
** Party contacts: campaign booth
**
********************************************************************************

// Neutral values

foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_stand`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_stand1`welle'= kp`welle'_421ha==1
   replace pk_stand4`welle'= kp`welle'_421hc==1 
   replace pk_stand5`welle'= kp`welle'_421hd==1 
   replace pk_stand6`welle'= kp`welle'_421he==1 
   replace pk_stand7`welle'= kp`welle'_421hf==1 
}


********************************************************************************
**
** Party contacts: Post/E-Mail/SMS
**
********************************************************************************

// Neutral values

foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_postemsms`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_postemsms1`welle'= kp`welle'_421ba==1
   replace pk_postemsms4`welle'= kp`welle'_421bc==1 
   replace pk_postemsms5`welle'= kp`welle'_421bd==1 
   replace pk_postemsms6`welle'= kp`welle'_421be==1 
   replace pk_postemsms7`welle'= kp`welle'_421bf==1 
}


********************************************************************************
**
** Party contacts: donation
**
********************************************************************************

// Neutral values


foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_spende`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_spende1`welle'= kp`welle'_421la==1
   replace pk_spende4`welle'= kp`welle'_421lc==1 
   replace pk_spende5`welle'= kp`welle'_421ld==1 
   replace pk_spende6`welle'= kp`welle'_421le==1 
   replace pk_spende7`welle'= kp`welle'_421lf==1 
}

********************************************************************************
**
** Party contacts: social network
**
********************************************************************************

// Neutral values


foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_soznetz`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_soznetz1`welle'= kp`welle'_421ia==1
   replace pk_soznetz4`welle'= kp`welle'_421ic==1 
   replace pk_soznetz5`welle'= kp`welle'_421id==1 
   replace pk_soznetz6`welle'= kp`welle'_421ie==1 
   replace pk_soznetz7`welle'= kp`welle'_421if==1 
}


*****************************************************************************
**				Party contacts set missings							**
***																			**
******************************************************************************

foreach welle of numlist 2/7 {
foreach partei of numlist 1 4/7 {
foreach var in soznetz spende tvspot kundgeb ///
	radio plakat postemsms stand website {
replace pk_`var'`partei'`welle' = . if inlist(kp`welle'_421z, -99, -93, -95) 
replace pk_`var'`partei'`welle' = . if inlist(kp`welle'_421y, -99, -93, -95)
}
}
}
 

sum pk*


********************************************************************************
**
** Party contacts: index for each party
**
********************************************************************************

* Indexes for campaign contact with individual parties

foreach welle of numlist 2/7 {
foreach party of numlist 1 4/7 {
egen pk_gesamti`party'`welle' = anycount(pk_kundgeb`party'`welle' ///
	pk_tvspot`party'`welle' pk_radio`party'`welle'  ///
	pk_plakat`party'`welle' pk_postemsms`party'`welle' ///
	pk_stand`party'`welle' pk_website`party'`welle'), ///
	values(1)
replace pk_gesamti`party'`welle' = . if kp`welle'_421y<0 | kp`welle'_421z<0
gen pk_gesamtin`party'`welle' = pk_gesamti`party'`welle'/7
}
}

* W1: Assumption: constant to W2
foreach party of numlist 1 4/7 {
gen pk_gesamtin`party'1 = pk_gesamtin`party'2
}


sum pk_gesamtin*

drop pk_gesamti??
drop pk_kundgeb?? ///
	pk_tvspot?? pk_radio??  ///
	pk_plakat?? pk_postemsms?? ///
	pk_stand?? pk_website??
drop pk_soznetz?? pk_spende??


keep lfdn tvduell11-pk_gesamtin71

save "${path}\Reproducible Do-Files\Chapter 6\Data\komm_variablen13.dta", replace
   
